package org.jeecg.modules.iot.model;


import lombok.Data;

@Data
public class FieldStatus {

    private boolean acc;
    private boolean positioning;
    private boolean southLatitude;
    private boolean westLongitude;
    private boolean outOfService; // 停运状态
    private boolean encrypted;    // 经纬度加密
    private boolean riding;       // 骑行状态
    private int loadStatus;      // 载重状态 (0:空车, 1:半载, 3:满载)
    private boolean oilCircuitNormal; // 油路正常
    private boolean circuitNormal;    // 电路正常
    private boolean doorLocked;      // 车门加锁
    private boolean door1Open;       // 门 1 开
    private boolean door2Open;       // 门 2 开
    private boolean door3Open;       // 门 3 开
    private boolean door4Open;       // 门 4 开
    private boolean door5Open;       // 门 5 开
    private boolean gpsUsed;
    private boolean beidouUsed;
    private boolean glonassUsed;
    private boolean galileoUsed;
    private boolean engineStarted;  // 发动机启动状态
    private boolean remoteStart;
    private boolean sportMode; //  添加运动模式状态



    public FieldStatus(Integer status) {
        this.acc = (status & 0x00000001) != 0;
        this.positioning = (status & 0x00000002) != 0;
        this.southLatitude = (status & 0x00000004) != 0;
        this.westLongitude = (status & 0x00000008) != 0;
        this.outOfService = (status & 0x00000010) != 0;
        this.encrypted = (status & 0x00000020) != 0;
        this.riding = (status & 0x00000040) != 0;
        this.loadStatus = (status >> 8) & 0x03;  //  8-9 位
        this.oilCircuitNormal = (status & 0x00000400) == 0; //  10 位, 0 表示正常
        this.circuitNormal = (status & 0x00000800) == 0;    //  11 位, 0 表示正常
        this.doorLocked = (status & 0x00001000) != 0;      //  12 位
        this.door1Open = (status & 0x00002000) != 0;       //  13 位
        this.door2Open = (status & 0x00004000) != 0;       //  14 位
        this.door3Open = (status & 0x00008000) != 0;       //  15 位
        this.door4Open = (status & 0x00010000) != 0;       //  16 位
        this.door5Open = (status & 0x00020000) != 0;       //  17 位
        this.gpsUsed = (status & 0x00040000) != 0;        //  18 位
        this.beidouUsed = (status & 0x00080000) != 0;       //  19 位
        this.glonassUsed = (status & 0x00100000) != 0;      //  20 位
        this.galileoUsed = (status & 0x00200000) != 0;      //  21 位
        this.engineStarted = (status & 0x40000000) != 0;   //  30 位
        this.remoteStart = (status & 0x80000000) != 0;    //  31 位
    }


    @Override
    public String toString() {
        return "车辆状态{" +
                "ACC=" + (acc ? "开启" : "关闭") +
                ", 定位=" + (positioning ? "已定位" : "未定位") +
                ", 纬度=" + (southLatitude ? "南纬" : "北纬") +
                ", 经度=" + (westLongitude ? "西经" : "东经") +
                ", 停运=" + (outOfService ? "停运" : "运营") +
                ", 加密=" + (encrypted ? "已加密" : "未加密") +
                ", 骑行=" + (riding ? "骑行中" : "静止") +
                ", 载重状态=" + getLoadStatusString(loadStatus) + // 使用辅助方法获取中文描述
                ", 油路=" + (oilCircuitNormal ? "正常" : "断开") +
                ", 电路=" + (circuitNormal ? "正常" : "断开") +
                ", 车门锁（设防状态）=" + (doorLocked ? "已加锁" : "未加锁") +
                ", 右前门=" + (door1Open ? "打开" : "关闭") +
                ", 左后门=" + (door2Open ? "打开" : "关闭") +
                ", 右后门=" + (door3Open ? "打开" : "关闭") +
                ", 驾驶席门=" + (door4Open ? "打开" : "关闭") +
                ", 尾箱门=" + (door5Open ? "打开" : "关闭") +
                ", GPS=" + (gpsUsed ? "已使用" : "未使用") +
                ", 北斗=" + (beidouUsed ? "已使用" : "未使用") +
                ", GLONASS=" + (glonassUsed ? "已使用" : "未使用") +
                ", Galileo=" + (galileoUsed ? "已使用" : "未使用") +
                ", 发动机=" + (engineStarted ? "启动" : "熄火") +
                ", 远程启动=" + (remoteStart ? "远程启动" : "本地启动") +
                '}';
    }

    // 辅助方法，将载重状态转换为中文描述
    private String getLoadStatusString(int loadStatus) {
        switch (loadStatus) {
            case 0:
                return "空车";
            case 1:
                return "半载";
            case 3:
                return "满载";
            default:
                return "未知"; //  或其他默认值
        }
    }
}